<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>管理员</title>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.pagination.js"></script>
<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/public.js"></script>
<script type="text/javascript" src="../../js/alert.js"></script>
<script type="text/javascript" src="../../js/loadSchoolGrade.js"></script>
<script type="text/javascript" src="../../js/jquery-ui/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../js/jquery-ui/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.css">
</head>
<body>
	<table class="table table-bordered" id="datas">
		<tr>
			<td name="id" other="bindDriver"></td>
			<td name="name">姓名</td>
			<td name="sex">性别</td>
			<td name="mobile">手机号</td>
			<td name="idCard">身份证号</td>
		</tr>
	</table>
	
	<!-- 分页控件 -->
    <div class="pager">
    </div>
</body>
	<script type="text/javascript">
		var href = location.href.split("=");
		var schoolId = href[1];
		searchPage(1,10);
		var id = "";//用于存放被选中的教练员的ID
		var mount = "";
		//获取该驾校的所有教练员信息
		function searchPage(pageNo,pageSize){
			$.ajax({
				url : "../../driver/getDriversBySchoolId.ao",
				type : 'POST',
				data : {
					"id" : schoolId,
					"pageNo" : pageNo,
					"pageSize" : pageSize
				},
				beforeSend : ajaxstar,
    			complete : ajaxend,
    			cache : false,
    			dataType : "json",
    			success : function(data){
    				if (data["state"] == "success") {
    					var str = "";
    					if(data["pageNo"] <= 1){//只有在第一页的时候才会初始化分页控件
    					    $(".pager").pagination({
    					        recordCount: data["recordTotalCount"],       //总记录数
    					        pageSize: data["pageSize"],           		//一页记录数
    					        onPageChange: function (pageIndex) {
    					        	searchPage(pageIndex,data["pageSize"]);
    					        }
    					    });
    					}
						str = "<table class=\"table table-bordered .table-condensed\"><tr><td></td><td>ID</td><td>教练员姓名</td><td>性别</td><td>手机号</td><td>身份证号</td>";
						if(data["result"].length>0){
							for(var i=0;i<data["result"].length;i++){
								mount = data["result"].length;
								str += "<tr>";
								str += "<td><label><input type=\"radio\" name=\"radios\" class=\"minimal-red\"  id=\"radio"+i+"\" value='" + data["result"][i]["id"] + "'/></label></td>";
								str += "<td id='id"+i+"'> "+data["result"][i]["id"]+" </td>";
								str += "<td id='name"+i+"'>"+data["result"][i]["name"]+"</td>";
								str += "<td id='sex"+i+"'>"+data["result"][i]["sex"]+"</td>";
								str += "<td id='level"+i+"'>"+data["result"][i]["mobile"]+"</td>";
								str += "<td id='idCard"+i+"'>"+data["result"][i]["idCard"]+"</td>"
								str += "</tr>";
							}
							str += "<tr>";
							str += "<td colspan='6' style='text-align: center;'>";
							str += "<button type='button' onclick='bindDriver();' class='btn btn-info'>确定</button>";
							str += "</td>";
							str += "</tr>";
							$("#datas").html(str);
						}else{
							str += "<tr>";
							str += "<td colspan='10' style='text-align:center;color:blue;'>无搜索结果</td>";
							str += "</tr>";
							$("#datas").html(str);
						}
    				} else {
    					sAlert(data["result"]);
    				}
    			}
			});
		}
		
		//设置教练员信息到主页面
		function bindDriver(){
			var driverName = "";
			for(var i = 0; i < mount; i++){
				var flag =  document.getElementById("radio"+i).checked;
				if(flag){
					id = $("#id" + i).html();
					driverName = $("#name" + i).html();
				}
				window.parent.quit();
				window.parent.setCarManage(id,driverName);
			}
		}	
	</script>
</html>